package com.ms.game.invitefriend.db;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.ms.game.invitefriend.bin.InviteCodeType;
import com.xpec.c4.db.model.basic.BasicGameModel;
import com.xpec.c4.game.time.TimeSys;


@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "invite_codes", uniqueConstraints = { @UniqueConstraint(columnNames = { "inviteCode" }) })
@org.hibernate.annotations.Table(
		appliesTo = "invite_codes", indexes = {
				@org.hibernate.annotations.Index(name = "INDEX_PLAYER_TYPE", columnNames = { "playerId","type" }),
				@org.hibernate.annotations.Index(name = "INDEX_INVITE_CODE", columnNames = { "inviteCode" }),
				@org.hibernate.annotations.Index(name = "INDEX_USED", columnNames = { "type", "inviteCode"})
		})
public class InviteCodeModel extends BasicGameModel {
	private static final long serialVersionUID = 1818030885345751099L;
	
	
	public InviteCodeModel() {
		eventTime = Calendar.getInstance();
		createTime = TimeSys.currentTimeMills();
	}
	
	
	/** 
	 * 紀錄時間
	 */
	private Calendar eventTime;
	
	/** 
	 * 遊戲時間
	 */
	private long createTime; 

	/**
	 * type
	 */
	private InviteCodeType type;

	/**
	 * 擁有此邀請碼的角色ID
	 */
	private String playerId;
	
	/**
	 * 邀請碼  
	 */
	private String inviteCode;
	
	/**
	 * 截止時間
	 */
	private long expiration;
	
	/**
	 * 備註
	 */
	private String notes;
	
	/**
	 * 邀請碼使用的人數上限
	 */
	private Integer upperLimit;
	
	/**
	 * 是否是只能給一個人用
	 * true : 單人 
	 * false : 多人
	 */
	private boolean singleUse = false;

	private boolean haveBeenUsed = false;
	
	/**
	 * 群組的邀請碼的orderId
	 */
	private String groupId; 
	
	/**
	 * 群組邀請碼內的序號
	 */
	private Integer snInGroup;

	/**
	 * 是否作廢
	 */
	private boolean invalid;
	
	public Calendar getEventTime() {
		return eventTime;
	}

	public void setEventTime(Calendar eventTime) {
		this.eventTime = eventTime;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public String getPlayerId() {
		return playerId;
	}

	public void setPlayerId(String playerId) {
		this.playerId = playerId;
	}

	public String getInviteCode() {
		return inviteCode;
	}

	public void setInviteCode(String inviteCode) {
		this.inviteCode = inviteCode;
	}

	public long getExpiration() {
		return expiration;
	}

	public void setExpiration(long expiration) {
		this.expiration = expiration;
	}
	
	@Enumerated(EnumType.STRING)
	public InviteCodeType getType() {
		return type;
	}

	public void setType(InviteCodeType type) {
		this.type = type;
	}	
	
	public boolean isHaveBeenUsed() {
		return haveBeenUsed;
	}

	public void setHaveBeenUsed(boolean haveBeenUsed) {
		this.haveBeenUsed = haveBeenUsed;
	}
	
	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}
	
	public boolean isSingleUse() {
		return singleUse;
	}

	public void setSingleUse(boolean singleUse) {
		this.singleUse = singleUse;
	}

	public Integer getUpperLimit() {
		return upperLimit;
	}

	public void setUpperLimit(Integer upperLimit) {
		this.upperLimit = upperLimit;
	}

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	public Integer getSnInGroup() {
		return snInGroup;
	}

	public void setSnInGroup(Integer snInGroup) {
		this.snInGroup = snInGroup;
	}

	@Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT false")
	public boolean isInvalid() {
		return invalid;
	}

	public void setInvalid(boolean invalid) {
		this.invalid = invalid;
	}
}